Skip to content

test: prefer github app auth in integration fixtures#790

Merged
cbartz merged 15 commits intomainfrom
feat/integration-github-app-auth-fallback
Apr 22, 2026
Merged

test: prefer github app auth in integration fixtures#790
cbartz merged 15 commits intomainfrom
feat/integration-github-app-auth-fallback

Conversation

@cbartz
Copy link
Copy Markdown
Collaborator

@cbartz cbartz commented Apr 20, 2026

What this PR does

Teach the integration test fixtures to prefer GitHub App authentication when credentials are available, falling back to PAT otherwise. Along the way, clean up the surrounding plumbing:

  • The shared github_config fixture (both root charm and github-runner-manager) returns a GitHubConfig populated with app credentials when all three of GITHUB_APP_CLIENT_ID, GITHUB_APP_INSTALLATION_ID, and GITHUB_APP_PRIVATE_KEY are present. Otherwise token auth is used. The ad-hoc override inside test_e2e.py is gone.
  • Drop the test_charm_fork_path_change integration test and its workflow entry, along with the now-dead INTEGRATION_TOKEN_ALT / --github-token-alt / alt_token plumbing that only existed for that test.
  • INTEGRATION_TOKEN and GITHUB_APP_PRIVATE_KEY are read from env vars only — no more --github-token pytest CLI flag — keeping secrets off the process command line.
  • Replace the per-slot "which env var lives here" comments in the workflows with a pointer to CONTRIBUTING.md, which is the authoritative place for the slot-to-var mapping. The inline comments rot silently when the mapping is reshuffled in repo settings.
  • Wire three additional secret slots (INTEGRATION_TEST_SECRET_ENV_VALUE, _11, _12) in test_github_runner_manager.yaml to carry the app credentials.
  • integration_test.yaml now forwards --github-app-client-id from vars.INTEGRATION_TEST_GITHUB_APP_CLIENT_ID, matching the pattern already in e2e_test.yaml.

Why we need it

PATs are bound to individual people, so any rotation or role change risks breaking CI. Using a GitHub App is cleaner: credentials belong to the project, not a person, and the same auth path is exercised that the charm uses in production.

Checklist

  • I followed the contributing guide
  • I added or updated the documentation (if applicable)
  • I updated `docs/changelog.md` with user-relevant changes
  • I used AI to assist with preparing this PR
  • I added or updated tests as needed (unit and integration)
  • If this is a Grafana dashboard: I added a screenshot of the dashboard
  • If this is Terraform: `terraform fmt` passes and `tflint` reports no errors
  • If the github-runner-manager application has been changed: The application version number is updated in `github-runner-manager/pyproject.toml`.

@cbartz cbartz force-pushed the feat/integration-github-app-auth-fallback branch from 6fa227a to 0aea0b4 Compare April 21, 2026 10:18
cbartz added 6 commits April 21, 2026 12:36
The second GitHub token was only needed for the fork-path-change tests
that were removed in recent commits. Drop the now-dead --github-token-alt
option, INTEGRATION_TOKEN_ALT env plumbing, and alt_token field.
The inline comments naming which env var fills each
INTEGRATION_TEST_SECRET_ENV_VALUE_<N> slot could silently desync when
the mapping is reshuffled in repo settings. Point to CONTRIBUTING.md
instead, which is the authoritative source.
Drop the --github-token pytest option so the token can only flow through
the INTEGRATION_TOKEN environment variable. Matches how
GITHUB_APP_PRIVATE_KEY is already handled and keeps secrets out of the
process command line.
Add the unsuffixed INTEGRATION_TEST_SECRET_ENV_NAME slot plus _11 and
_12 so the GitHub App client id, installation id, and private key can
be delivered to integration tests.
Mirror the e2e workflow and forward INTEGRATION_TEST_GITHUB_APP_CLIENT_ID
into the charm integration test jobs so they can opt into GitHub App
authentication when the other app credentials are available.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the integration-test fixture plumbing to prefer GitHub App authentication when the necessary credentials are available, while retaining PAT-based behavior as a fallback and removing fork/alt-token paths that are no longer needed.

Changes:

  • Prefer GitHub App auth in shared integration github_config fixtures (root charm and github-runner-manager) when app credentials are present; otherwise use token auth.
  • Remove the fork/path-change integration test and the associated alternate-token plumbing (INTEGRATION_TOKEN_ALT, --github-token-alt, etc.).
  • Update CI workflows and tox passthrough to support the revised secret/env-var approach (including additional secret slots for app credentials).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tox.ini Stops passing INTEGRATION_TOKEN_ALT into the root integration tox env.
tests/integration/test_e2e.py Removes the module-local github_config override so the shared fixture behavior applies.
tests/integration/test_charm_fork_path_change.py Deletes the fork/path-change integration test module.
tests/integration/conftest.py Centralizes GitHub App vs PAT selection in the shared github_config fixture; removes fork-related fixtures/plumbing.
tests/conftest.py Removes the --github-app-private-key CLI option (private key now env-only).
github-runner-manager/tox.ini Stops passing INTEGRATION_TOKEN_ALT into the manager integration tox env.
github-runner-manager/tests/unit/test_integration_factories.py Adds unit coverage for factories producing token-auth vs app-auth configs.
github-runner-manager/tests/integration/factories.py Refactors GitHubConfig to support GitHub App auth and emits the appropriate auth block.
github-runner-manager/tests/integration/conftest.py Prefers GitHub App auth when app credentials are available; token is now env-only.
github-runner-manager/tests/conftest.py Removes old token/alt-token CLI options; adds GitHub App client/installation CLI options.
.github/workflows/test_github_runner_manager.yaml Updates secret-slot wiring to carry GitHub App credentials and references CONTRIBUTING.md for mapping.
.github/workflows/integration_test.yaml Removes the deleted fork test from the matrix and forwards --github-app-client-id consistently.

Comment thread github-runner-manager/tests/integration/conftest.py Outdated
cbartz added 2 commits April 21, 2026 15:17
Mark the token, private key, and OpenStack password fields with
repr=False so assertion failures, traceback locals, or stray logs of
these dataclasses cannot leak credentials in transformed (non-masked)
forms.
Token and private key are env-only; path and app IDs come from pytest
options. Prior docstring said "pytest options or environment" without
distinguishing which inputs come from where.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comment thread github-runner-manager/tests/conftest.py
Comment thread github-runner-manager/tests/integration/conftest.py Outdated
cbartz added 2 commits April 21, 2026 15:49
Only --github-app-client-id and --github-app-installation-id fall back
to env vars; --github-repository does not. Previous wording implied all
three did.
Earlier revert commit moved two any_charm blocks to a multi-line form
that the current black config rejects. Match main's inline style so
lint passes.
Comment thread github-runner-manager/tests/integration/factories.py
Comment thread github-runner-manager/tests/conftest.py
Comment thread tests/integration/test_charm_fork_path_change.py
Comment thread tests/integration/test_charm_upgrade.py
Comment thread tests/conftest.py
@cbartz cbartz marked this pull request as ready for review April 21, 2026 14:01
Copy link
Copy Markdown
Member

@yanksyoon yanksyoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for catching the security related issues!

Comment thread .github/workflows/test_github_runner_manager.yaml
@cbartz cbartz merged commit fa6312d into main Apr 22, 2026
137 of 158 checks passed
@cbartz cbartz deleted the feat/integration-github-app-auth-fallback branch April 22, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants